import Taro, {Component} from '@tarojs/taro'
import {View, Text, Button} from '@tarojs/components'
import {connect} from '@tarojs/redux'

import './topic.scss'

class Topic extends Component {
  toDetail (id) {
    const url = `/pages/detail/index?topicid=${id}`
    Taro.navigateTo({url})
  }
  render () {
    let {item} = this.props
    return (
      <View className='topic-contaner' onClick={this.toDetail.bind(this, item.id)}>
        <Image className='head-img' src={item.author ? item.author.avatar_url : ''} />
        <View className='right'>
          <View className='topic-title'>
            <Text className='topic-up'>
              {
                item.top ? '置顶' : (item.tab === 'share' ? '分享' : '问答')
              }
            </Text>
            <Text>{item.title}</Text>
          </View>
          <View className='topic-info'>
            <Text>{item.author ? item.author.loginname: ''}</Text>
            <Text>{item.reply_count + '/' + item.visit_count}</Text>
            <Text>{item.create_at}</Text>
          </View>
        </View>
      </View>
    )
  }
}

export default Topic